export function compareTimestamp(timestamp) {
    const now = Date.now();
    const diff = now - timestamp;

    if (diff < 0) return null; // 处理未来时间

    const minuteMs = 60 * 1000;
    const hourMs = 60 * minuteMs;
    const dayMs = 24 * hourMs;
    const monthMs = 30 * dayMs; // 按30天近似为一个月
    const threeMonthsMs = 3 * monthMs;

    if (diff < minuteMs) {
        return '1分钟内';
    } else if (diff < hourMs) {
        const minutes = Math.floor(diff / minuteMs);
        return `${minutes}分钟前`;
    } else if (diff < dayMs) {
        const hours = Math.floor(diff / hourMs);
        return `${hours}小时前`;
    } else if (diff < monthMs) {
        const days = Math.floor(diff / dayMs);
        return `${days}天前`;
    } else if (diff <= threeMonthsMs) {
        const months = Math.floor(diff / monthMs);
        return `${months}个月前`;
    } else {
        return null;
    }
}